package com.kaihong.template.ble.utils;

import ohos.bluetooth.ble.BleScanFilter;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Ble filter util class
 */
public class BleScanFilterUtil {
    private BleScanFilterUtil() {
    }

    /**
     * Get filter list by uuid
     *
     * @param services uuid array
     * @return filter list
     */
    public static List<BleScanFilter> getBleScanFilterListByUuidArray(UUID[] services) {
        if (services == null || services.length == 0) {
            return new ArrayList<>(0);
        }
        List<BleScanFilter> bleScanFilterList = new ArrayList<>();
        for (UUID uuid : services) {
            BleScanFilter bleScanFilter = new BleScanFilter();
            bleScanFilter.setPeripheralServiceUuid(uuid, null);
            bleScanFilterList.add(bleScanFilter);
        }
        return bleScanFilterList;
    }

    /**
     * Get filter list by mac address
     *
     * @param macAddresses mac Addresses
     * @return list of filter
     */
    public static List<BleScanFilter> getBleScanFilterListByMacArray(String[] macAddresses) {
        if (macAddresses == null || macAddresses.length == 0) {
            return new ArrayList<>(0);
        }
        List<BleScanFilter> bleScanFilterList = new ArrayList<>();
        for (String macAddress : macAddresses) {
            BleScanFilter bleScanFilter = new BleScanFilter();
            bleScanFilter.setPeripheralAddress(macAddress);
            bleScanFilterList.add(bleScanFilter);
        }
        return bleScanFilterList;
    }
}
